<!-- 选择零件号 -->
<template>
  <div id="dialog-container">
    <el-button  @click="dialogVisible = true">选择</el-button>
    <el-dialog v-dialogDrag :title="'选择人员'" append-to-body :visible.sync="dialogVisible" :close-on-click-modal="false" :before-close="handleClose" width="680px">
      <el-form :model="formData" :inline="true" label-width="100px" size="small">
        <el-form-item label="工号：">
          <el-input v-model="formData.username"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button style="float:right" type="primary" @click="showList">查询</el-button>
        </el-form-item>
        <!-- <el-form-item label="姓名：">
          <el-input v-model="formData.name"></el-input>
        </el-form-item> -->
        <!-- <el-form-item label="工号：">
          <el-input v-model="formData.empNo"></el-input>
        </el-form-item> -->
      </el-form>
      <el-table ref="multipleTable" :data="tableData" @selection-change="handleSelectionChange"
        :row-key="getRowKeys">
        <el-table-column type="selection" width="50" :reserve-selection="true" align="center"></el-table-column>
        <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
        <el-table-column prop="username" label="工号"  width="" align="center"></el-table-column>
        <el-table-column prop="name" label="姓名" width="" align="center"></el-table-column>
        <!-- <el-table-column prop="empNo" label="工号" align="center"></el-table-column> -->
      </el-table>
      <el-row type="flex" justify="center" v-if="this.formData.username==''">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="pageSizeArr"
          :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageTotal"></el-pagination>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitChoose">确 定</el-button>
        <el-button @click="cancel()">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { getByInUsername } from 'service/task';
  export default {
    data() {
      return {
        dialogVisible: false,
        formData: {
          username: '',
          name: '',
          empNo: '',
        },
        tableData: [],
        name: [],
        id: [],
        currentPage: 1,
        pageSizeArr: [10, 20, 50, 100],
        pageSize: 10,
        pageTotal: 0,
        page: 0,
        totalElements: 0
      }
    },
    mounted() {
      this.showList();
    },
    methods: {
      getRowKeys(row) {
            return row.username;
      },
      showList() {
         getByInUsername({
          username: this.formData.username,
          name: this.formData.name,
          empNo: this.formData.empNo,
          pageNumber: this.currentPage,
          pageSize: this.pageSize,
          sort:"",
          order: ""
        }).then(res => {
          if(this.formData.username!=''){
            this.tableData =res.data.result;
          }else{
            this.tableData =res.data.result.content;
           this.pageSize = res.data.result.pageable.pageSize;
          this.pageTotal = res.data.result.totalElements;
          this.totalElements = res.data.result.totalElements;
          }
        })
      },
      handleCurrentChange(val) {
      this.currentPage = val;
      this.showList();
      },
      clearForm() {
      this.partGraphNumber = '';
      this.partName = '';
      this.partNumber = '';
      this.showList();
      },
      handleSizeChange(val){
        this.pageSize = val;
        this.showList();
      },
      handleSelectionChange(val) {
        
         for(var i = 0; i < val.length; i++) {
          this.name.splice(val[i].name);
           this.id.splice(val[i].id);
        };
         for(var i = 0; i < val.length; i++) {
          this.name.push(val[i].name);
           this.id.push(val[i].id);
        };
        this.name = this.name.filter(function(element,index,self) {
          return self.indexOf(element) === index;
        })
        this.id = this.id.filter(function(element,index,self) {
          return self.indexOf(element) === index;
        })
      },
      cancel(){
        this.formData={
          username: '',
          name: '',
          empNo: '',
        };
        this.showList();
        this.$refs.multipleTable.clearSelection();
        this.dialogVisible = false;
      },
      handleClose(){
        this.formData={
          username: '',
          name: '',
          empNo: '',
        };
        this.showList();
        this.$refs.multipleTable.clearSelection();
        this.dialogVisible = false;
      },
      // 确定
      submitChoose() {
        // console.log(9)
        if(this.name === "") {
          this.$alert('请选择一条数据！', '提示', {
            type: 'warning'
          })
        } else {
          this.$emit("acceptUidVal", this.name.join(","), this.id.join(","));
          this.name.splice(0, this.name.length);
          this.id.splice(0, this.id.length);
          this.dialogVisible = false;
          this.$refs.multipleTable.clearSelection();
          this.formData={
          username: '',
          name: '',
          empNo: '',
        };
        this.showList();
        }
      }
    }
  }

</script>
